package edu.chinasoft.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import javax.servlet.annotation.WebServlet;
import org.apache.log4j.Logger;

/**
 * 
 * @author cjogng
 * @date 2020年1月17日:下午4:39:20
 * @version V1.0
 * @Description: 显示足迹
*/
@WebServlet(name="myShowZuJiForServlet",value="/servlet/showzujiforservlet")
public class  ShowZuJiForServlet  extends HttpServlet {
	private static Logger logger = Logger.getLogger( ShowZuJiForServlet .class);
	
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" ShowZuJiForServlet >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		out.write("<!DOCTYPE html>     <html lang='en'>     <head>     	<meta charset='UTF-8'>     	<title>我的足迹</title>     </head>     <body>          <dl>     	<dt><h3>我的足迹：</h3></dt>");
		//获取cookie里的内容
		
		Cookie[] cookieArray = request.getCookies();
		String cookieValue="";
		if(cookieArray!=null) {
			for(Cookie element:cookieArray) {
				if(element.getName().equals("lookgoods")) {
					cookieValue=element.getValue();
				}
				
			}
			
		}
		
		if(cookieValue.equals("")) {
			out.write("<dd>没有查看商品信息</dd>");
		}else {
			String[] id_Name_Array = cookieValue.split("#");
			for(String elemet_Id_Name:id_Name_Array) {
				String id = elemet_Id_Name.split(":")[0];
				String name= elemet_Id_Name.split(":")[1];
				out.write("<dd><a href='"+request.getContextPath()+"/servlet/findgoodsbyidforservlet?id="+id+"'>"+name+"</a></dd>");
			}
			
			
		}
		
		
		
		
		
		out.write("</dl></body></html>");		
		logger.debug(" ShowZuJiForServlet >doGet end.......");
	}
	
	/**
	 * 
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" ShowZuJiForServlet >doPost start.......");
		this.doGet(request, response);
		
		logger.debug(" ShowZuJiForServlet >doPost end.......");
	}
	
}